package classes.controlers {
	import classes.controlers.jumpRabbit.JumpRabbit;
	import classes.managers.Game_Manager;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class Jump_Rabbits_Controler {
		private var gm:Game_Manager;
		
		private var rabbitCnt:int = 1;
		
		private var rabbit1:JumpRabbit;
		private var rabbit2:JumpRabbit;
		private var rabbit3:JumpRabbit;
		private var rabbit4:JumpRabbit;
		private var rabbit5:JumpRabbit;
		private var rabbit6:JumpRabbit;
		private var rabbit7:JumpRabbit;
		
		public function Jump_Rabbits_Controler( _gm:Game_Manager, _arr:Array ) {
			gm = _gm;

			rabbit1 = new JumpRabbit( gm, this, _arr[0] );
			rabbit2 = new JumpRabbit( gm, this, _arr[1] );
			rabbit3 = new JumpRabbit( gm, this, _arr[2] );
			rabbit4 = new JumpRabbit( gm, this, _arr[3] );
			rabbit5 = new JumpRabbit( gm, this, _arr[4] );
			rabbit6 = new JumpRabbit( gm, this, _arr[5] );
			rabbit7 = new JumpRabbit( gm, this, _arr[6] );
		}
		
		public function init():void {
			rabbit1.init(); rabbit1.visible = true;
			rabbit2.init();
			rabbit3.init();
			rabbit4.init();
			rabbit5.init();
			rabbit6.init();
			rabbit7.init();
			
			rabbitCnt = 1;
		}
		
		public function arrowMark( _cnt:int ):void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				if ( i <= _cnt ) {
					this["rabbit" + i].arrowONOFF = true;
				}
			}
		}
		
		public function enterRabbits():void {
			switch ( rabbitCnt ) {
				case 1: rabbit1.enterPlay(); rabbit1.visible = true;
				break;
				case 2: rabbit2.enterPlay(); rabbit2.visible = true;
				break;
				case 3: rabbit3.enterPlay(); rabbit3.visible = true;
				break;
				case 4: rabbit4.enterPlay(); rabbit4.visible = true;
				break;
				case 5: rabbit5.enterPlay(); rabbit5.visible = true;
				break;
				case 6: rabbit6.enterPlay(); rabbit6.visible = true;
				break;
				case 7: rabbit7.enterPlay(); rabbit7.visible = true;
				break;
				default:
			}
			rabbitCnt++;
		}
		
		public function readyRabbits( _cnt:int ):void {
			switch ( _cnt ) {
				case 1: rabbit1.readyPlay();
				break;
				case 2: rabbit2.readyPlay();
				break;
				case 3: rabbit3.readyPlay();
				break;
				case 4: rabbit4.readyPlay();
				break;
				case 5: rabbit5.readyPlay();
				break;
				case 6: rabbit6.readyPlay();
				break;
				case 7: rabbit7.readyPlay();
				break;
				default:
			}
		}
		
		public function fallRabbits( _cnt:int ):void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				if ( i <= _cnt ) {
					this["rabbit" + i].fallPlay();
				}
			}
		}
		
		public function jumpRabbits():void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				this["rabbit" + i].jumpPlay();
			}
		}
		
		public function nomalRabbits( _cnt:int ):void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				if ( i <= _cnt ) {
					this["rabbit" + i].nomalPlay();
				}
			}
		}
		
		public function swapRope1( _parent:MovieClip, _rope:MovieClip ):void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				var rabbit:JumpRabbit = this["rabbit" + i];
				if ( rabbit.enterEND ) {
					//trace(_parent.getChildIndex(_rope))
					_parent.setChildIndex( rabbit.mc, (_parent.getChildIndex(_rope)-1) );
				}
			}
		}
		
		public function swapRope2( _parent:MovieClip, _rope:MovieClip ):void {
			var i:int;
			var length:int = 7;
			for ( i = 1; i <= length; ++i ) {
				var rabbit:JumpRabbit = this["rabbit" + i];
				if ( rabbit.enterEND ) {
					_parent.setChildIndex( rabbit.mc, (_parent.getChildIndex(_rope)+1) );
				}
			}
		}
	}

}